package com.hxd.mall.module.usercenter.settings

import com.hxd.mall.constant.HxdConstantsAccount.isLogin
import com.hxd.mall.constant.HxdConstantsRouterPath.Product.path_hxd_main_page
import com.hxd.mall.module.EventBean
import com.hxd.mall.module.MainActivity
import com.hxd.mall.network.base.BaseRequest
import com.hxd.mall.network.service.ManagerFunctionApi
import com.hxd.mall.network.service.ManagerFunctionApi.mIMeFunctionApi
import com.hxd.mall.utils.local.ActivityUtil
import com.hxd.mall.utils.local.ActivityUtil.sendEventBus
import com.hxd.mall.utils.local.RequestUtil
import com.hxd.mall.utils.local.StackManageUtil.closeOtherOnlyActivity
import com.hxd.mall.utils.open.ToastUtil
import java.util.*
import javax.inject.Inject

/**
 * @author zhaoyong
 * @description:
 * @date :2019/7/17 11:08 AM
 */
class SettingsPresenter @Inject constructor(var mView: ISettingsView) : ISettingsPresenter {
    override fun getflag() {

        BaseRequest.request(ManagerFunctionApi.mIAccountFunctionApi.flag, mView, {
            mView?.fetchFlag(it)
        }, {
            it.msg?.let { it1 -> ToastUtil.showToast(it1) }
        })
    }

    override fun logout() {
        BaseRequest.request(mIMeFunctionApi.logout(RequestUtil.getRequestBody(TreeMap())), mView, {
            if (it.code == 0) {
                ActivityUtil.clearUserInfo()
                closeOtherOnlyActivity(MainActivity(), path_hxd_main_page)
                sendEventBus(EventBean(0))
            } else {
                ToastUtil.showToast(it.msg ?: "")
            }
        }, {
            ToastUtil.showToast(it.msg ?: "")
        })
    }

    override fun getData() {
        BaseRequest.request(mIMeFunctionApi.settings, mView, {
            mView.showData(it)
        }, {

        })
    }

    override fun getVersionInfo() {
        /*BaseRequest.request(mMainFunctionApi!!.versionInfo, {
            mView.showData(it)
        }, {
            Logger.i("request fail")
        }, false)*/
    }
}